package com.kaibes.platform.file.client;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.kaibes.platform.file.client.db.FileServerService;
import com.kaibes.web.filter.BasicInterceptor;
import com.kaibes.web.response.ResponseFactory;
import com.kaibes.web.response.ResponseUtils;

@Component
public class FileClientInterceptor implements BasicInterceptor {

	@Autowired
	private ResponseUtils responseUtils;
	@Autowired
	private FileServerService fileServerService;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if (request.getRequestURI().startsWith("/files/maps") && fileServerService.countByGtPriority((short) 0)==0 ) {
			responseUtils.write(response, ResponseFactory.badRequest("请先配置文件服务器信息，再进行操作！"));
			return false;
		} 
		return BasicInterceptor.super.preHandle(request, response, handler);
	}
}
